﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GreatB2C.Config.SiteInfo;

namespace GreatB2C.Web.Manage.SystemSet.SiteInfo
{
    public partial class SiteParams : Inherit.ManagePage
    {
        protected void Page_Load( object sender , EventArgs e )
        {
            if ( !IsPostBack )
            {
                LoadSetting( );
            }
        }

        protected void LoadSetting( )
        {
            txtManageDir.Text = UIConfig.ManageDir.ToString( );
            txtTicketTime.Text = UIConfig.TicketTime.ToString( );
            radlEnableSiteManageCode.SelectedValue = UIConfig.EnableSiteManageCode.ToString( );
            txtSiteManageCode.Text = UIConfig.SiteMeta.ToString( );
            radlAdminIsLoginUser.SelectedValue = UIConfig.AdminIsLoginUser.ToString( );
            radlAdminIsLogoutUser.SelectedValue = UIConfig.AdminIsLogoutUser.ToString( );
            ddlCultureName.SelectedValue = UIConfig.CultureName.ToString( );
            radlEnableSoftKey.SelectedValue = UIConfig.EnableSoftKey.ToString( );
            txtMainDomain.Text = UIConfig.MainDomain.ToString( );
            radlConnProtecte.SelectedValue = UIConfig.ConnProtecte.ToString( );
            radlEnablePointMoneyExp.SelectedValue = UIConfig.PointMoneyExp.ToString( );
            txtADDir.Text = UIConfig.ADDir.ToString( );
            txtCreateHtmlPath.Text = UIConfig.CreateHtmlPath.ToString( );
            txtIncludeFilePath.Text = UIConfig.IncludeFilePath.ToString( );
            txtTemplateDir.Text = UIConfig.TemplateDir.ToString( );
            radlIsAutoSignin.SelectedValue = UIConfig.IsAutoSignin.ToString( );
            txtAutoSigninTime.Text = UIConfig.AutoSigninTime.ToString( );
            txtRefreshQueueSize.Text = UIConfig.RefreshQueueSize.ToString( );
            txtCollectionSleep.Text = UIConfig.CollectionSleep.ToString( );
            radlEnableRefreshHits.SelectedValue = UIConfig.EnableRefreshHits.ToString( );
            radlSiteStatus.SelectedValue = UIConfig.SiteStatus.ToString( );
            txtMailConfirmTemplate.Value = UIConfig.MailConfirmTemplate.ToString( );
            txtMailUnsubscribe.Value = UIConfig.MailUnsubscribe.ToString( );
            txtSiteMaintainDescription.Value = UIConfig.SiteMaintainDescription.ToString( );
        }

        protected void BtnSubmit_Click( object sender , EventArgs e )
        {
            bool isSuccess = UIConfig.Config( txtManageDir.Text.Trim( ) , txtTicketTime.Text.Trim( ) , radlEnableSiteManageCode.SelectedValue , txtSiteManageCode.Text.Trim( )
                , radlAdminIsLoginUser.SelectedValue.ToString( ) , radlAdminIsLogoutUser.SelectedValue.ToString( ) , ddlCultureName.SelectedValue.ToString( ) , radlEnableSoftKey.SelectedValue.ToString( )
                , txtMainDomain.Text.Trim( ) , radlConnProtecte.SelectedValue.ToString( ) , radlEnablePointMoneyExp.SelectedValue.ToString( ) , txtADDir.Text.Trim( )
                , txtCreateHtmlPath.Text.Trim( ) , txtIncludeFilePath.Text.Trim( ) , txtTemplateDir.Text.Trim( ) ,radlIsAutoSignin.SelectedValue.ToString( )
                , txtAutoSigninTime.Text.Trim( ) , txtRefreshQueueSize.Text.Trim( ) , txtCollectionSleep.Text.Trim( ) , radlEnableRefreshHits.SelectedValue.ToString( )
                , radlSiteStatus.SelectedValue.ToString( ) , txtMailConfirmTemplate.Value.Trim( ) , txtMailUnsubscribe.Value.Trim( ) , txtSiteMaintainDescription.Value.Trim( ) );

            if ( isSuccess )
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "网站参数配置成功！" ) + "&rtn=SystemSet/SiteInfo/SiteParams.aspx" );
            }
            else
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "网站参数配置失败，请联系管理员！" ) + "&rtn=SystemSet/SiteInfo/SiteParams.aspx" );
            }
        }
    }
}
